package logic

import (
	"context"
	"tieba/models/mysql"

	"tieba/tiebarpc/internal/svc"
	"tieba/tiebarpc/tiebarpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentsLogic {
	return &CommentsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CommentsLogic) Comments(in *tiebarpc.CommentsRequest) (*tiebarpc.CommentsResponse, error) {
	// todo: add your logic here and delete this line
	var com = mysql.Comment{
		UserId:  int(in.UserId),
		TieZiId: int(in.TieZiId),
		Content: in.Content,
	}
	mysql.DB.Debug().Create(&com)
	return &tiebarpc.CommentsResponse{
		ComId: int64(com.ID),
	}, nil
}
